﻿package org.urbanarmy.geturl
{
	import org.urbanarmy.utils.StringUtils;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.errors.*;
	
	/**
	* 	GetURL class by Ricardo Silva
	*
	*/
	public class GetURL
	{
		public function GetURL()
		{
			//
		}
		
		/**
		*	Function to mime getURL() function of AS2.
		*
		*	@param url The url - Default value: "" (String).
		*
		*	@param target The target - Default value: "_blank" (String).
		*
		*	@param validate Validate email - Default value: false (Boolean).
		*
		*	@returns Boolean
		*
		* 	@langversion ActionScript 3.0
		*	@playerversion Flash 9.0
		*/
		public static function link(url:String = "", target:String = "_blank", validate:Boolean = false):Boolean
		{
			var __result:Boolean;
			__result = validate ? StringUtils.validURL(url) : true;
			if (__result)
			{
				var request:URLRequest = new URLRequest(url);
				try {
					navigateToURL(request, target);
					return true;
				} catch (e:Error) {
					throw new Error("Error navigating to link");
					return false;
				}
			}
			throw new Error("Invalid link");
			return false;
		}
	}
}